package top.chmin.project.cloud.sys.config.info;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import top.chmin.project.cloud.common.*;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;



/**
 * chmin
 * 2024-01-25 14:19:00
 * cloud-code
 */
public class ConfigInfoCondition extends Condition {
    private ConfigInfoCondition parent = null;

    ConfigInfoCondition() {
    }

    private ConfigInfoCondition(ConfigInfoCondition condition) {
        this.parent = condition;
    }

    public static ConfigInfoCondition forDelete() {
        ConfigInfoCondition condition = new ConfigInfoCondition();
        condition.setSql("DELETE FROM sys_config_info#where##group##order##limit#");
        return condition;
    }

    public static ConfigInfoCondition forSelect() {
        ConfigInfoCondition condition = new ConfigInfoCondition();
        condition.modelClass = ConfigInfo.class;
        condition.setSql("SELECT #select# FROM sys_config_info#where##group##order##limit#");
        return condition;
    }

    public ConfigInfoCondition distinct() {
        this.distinct = true;
        return this;
    }

    public ConfigInfoCondition limit(int limit) {
        this.limit = " LIMIT " + limit;
        return this;
    }

    public ConfigInfoCondition sub() {
        return new ConfigInfoCondition(this);
    }

    public ConfigInfoCondition finish() {
        if (!whereList.isEmpty()) {
            parent.whereList.add("(" + String.join(" OR ", whereList) + ")");
        }
        parent.whereValueList.addAll(whereValueList);
        return parent;
    }

    public ConfigInfo selectFirst() {
        return selectFirst(ConfigInfo.class);
    }

    public List<ConfigInfo> selectList() {
        return selectList(ConfigInfo.class);
    }

    public Stream<ConfigInfo> selectStream() {
        return selectStream(ConfigInfo.class);
    }

    public Page<ConfigInfo> selectPage() {
        return selectPage(ConfigInfo.class);
    }

    /*###########auto#start###########*/
    public static int deleteByConfigCode(String configCode) {
        return forDelete().configCode().eq(configCode).execute();
    }

    public static ConfigInfo selectByConfigCode(String configCode) {
        return forSelect().configCode().eq(configCode).selectFirst(ConfigInfo.class);
    }

    public static <T> T selectByConfigCode(String configCode, Class<T> clazz) {
        return forSelect().configCode().eq(configCode).selectFirst(clazz);
    }

    public static int deleteByConfigName(String configName) {
        return forDelete().configName().eq(configName).execute();
    }

    public static ConfigInfo selectByConfigName(String configName) {
        return forSelect().configName().eq(configName).selectFirst(ConfigInfo.class);
    }

    public static <T> T selectByConfigName(String configName, Class<T> clazz) {
        return forSelect().configName().eq(configName).selectFirst(clazz);
    }

    /*###########auto##end############*/
    /* append $conditionIndexAppender$ */
    /*###########auto#start###########*/
    public ConfigCode configCode() {
        return new ConfigCode();
    }

    public class ConfigCode extends StringFlexColumn<ConfigInfoCondition> {
        private ConfigCode() {
            super(ConfigInfoCondition.this, "config_code");
        }
    }

    public ConfigName configName() {
        return new ConfigName();
    }

    public class ConfigName extends StringFlexColumn<ConfigInfoCondition> {
        private ConfigName() {
            super(ConfigInfoCondition.this, "config_name");
        }
    }

    public CreateBy createBy() {
        return new CreateBy();
    }

    public class CreateBy extends StringFlexColumn<ConfigInfoCondition> {
        private CreateBy() {
            super(ConfigInfoCondition.this, "create_by");
        }
    }

    public CreateTime createTime() {
        return new CreateTime();
    }

    public class CreateTime extends LocalDateTimeFlexColumn<ConfigInfoCondition> {
        private CreateTime() {
            super(ConfigInfoCondition.this, "create_time");
        }
    }

    public Id id() {
        return new Id();
    }

    public class Id extends IntegerFlexColumn<ConfigInfoCondition> {
        private Id() {
            super(ConfigInfoCondition.this, "id");
        }
    }

    public JavaPath javaPath() {
        return new JavaPath();
    }

    public class JavaPath extends StringFlexColumn<ConfigInfoCondition> {
        private JavaPath() {
            super(ConfigInfoCondition.this, "java_path");
        }
    }

    public UpdateBy updateBy() {
        return new UpdateBy();
    }

    public class UpdateBy extends StringFlexColumn<ConfigInfoCondition> {
        private UpdateBy() {
            super(ConfigInfoCondition.this, "update_by");
        }
    }

    public UpdateTime updateTime() {
        return new UpdateTime();
    }

    public class UpdateTime extends LocalDateTimeFlexColumn<ConfigInfoCondition> {
        private UpdateTime() {
            super(ConfigInfoCondition.this, "update_time");
        }
    }

    public VuePath vuePath() {
        return new VuePath();
    }

    public class VuePath extends StringFlexColumn<ConfigInfoCondition> {
        private VuePath() {
            super(ConfigInfoCondition.this, "vue_path");
        }
    }

    /*###########auto##end############*/
    /* append $conditionFieldAppender$ */
}
